package org.example.utils;

import org.example.common.GlobalConts;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import java.util.Date;

/**
 * @author 李国树
 * @version 1.0
 * @Desc
 * @date 2023/11/13 15:15
 */

public class EmailUtils {
    public static void sendEmail(JavaMailSender javaMailSender, String toEmail, String title, String body) {
        // 给用户发送邮件提示
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
//邮件发信人,注意一定要和配置文件中的邮件发送者保持一致
        simpleMailMessage.setFrom(GlobalConts.EMAIL_USERNAME);
//邮件收信人
        simpleMailMessage.setTo(toEmail);
//邮件主题
        simpleMailMessage.setSubject(title);
//邮件内容
        simpleMailMessage.setText(body);
//邮件发送时间
        simpleMailMessage.setSentDate(new Date());
//发送邮件
        javaMailSender.send(simpleMailMessage);
    }
}


